package cfca.seal.util;

import cfca.sadk.util.Base64;
import cfca.sadk.util.EncryptUtil;
import cfca.seal.exception.CodeException;

public class PwdEncryptUtil
{
  public static String encrypto(String input)
    throws CodeException
  {
    String ret = input;
    try {
      ret = new String(Base64.encode(EncryptUtil.encryptMessageBySM4(input.getBytes(), "1l10OO0O01lll1l1")));
    } catch (Exception e) {
      throw new CodeException("600404", e);
    }
    return ret;
  }

  public static String encrypto(byte[] input) throws CodeException {
    try {
      return new String(Base64.encode(EncryptUtil.encryptMessageBySM4(input, "1l10OO0O01lll1l1")));
    } catch (Exception e) {
      throw new CodeException("600404", e);
    }
  }

  public static String decrypto(String input)
    throws CodeException
  {
    String ret = input;
    try {
      byte[] data = Base64.decode(input);
      byte[] endata = EncryptUtil.decryptMessageBySM4(data, "1l10OO0O01lll1l1");
      ret = new String(endata);
    } catch (Exception e) {
      throw new CodeException("600405", e);
    }
    return ret;
  }
}